package com.mbd.field;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Клас, който обслужва JAVADOC
 * 
 * @author milena.bd@gmail.com
 */
public class Field {

	private static final int HEIGHT = 5;

	private static final int WIDTH = 5;

	private Map<Integer, List<Cell>> field = null;

	/**
	 * Конструктор
	 */
	public Field() {
		super();
		init();
	}

	private void init() {
		this.field = new HashMap<>();
		Integer key = null;
		for (int row = 0; row < HEIGHT; row++) {
			key = Integer.valueOf(row);
			getField().put(key, new ArrayList<Cell>());
			for (int col = 0; col < WIDTH; col++) {
				getField().get(key).add(new Cell(key, col));
			}
		}
	}

	public void addCell(Cell cell) {
		
		clearCellAt(cell.getRowNum(), cell.getColNum());

		getField().get(cell.getRowNum()).add(cell);

	}

	public void clearCellAt(Integer rowNum, Integer colNum) {
		
		getField().get(rowNum).remove(colNum);
	}

	@Override
	public String toString() {

		StringBuilder build = new StringBuilder();
		List<Cell> row = null;
		for(Integer key : getField().keySet()){
			row = getField().get(key);
			for(Cell currCell : row){
				build.append(currCell.toString());
			}
			build.append("\n");
		}

		return build.toString();
	}

	private Map<Integer, List<Cell>> getField() {
		return this.field;
	}
	
	

}
